package com.xb.loan.log;

import com.xb.loan.log.common.LogConfig;
import com.xb.loan.log.task.UserLogTask;
import com.xb.loan.util.SpringHelper;
import com.xb.loan.util.log.DefaultLoggerFacotry;
import com.xb.loan.util.log.LogFormatUtil;
import com.xb.loan.util.qrtz.TaskScheduleManager;
import org.slf4j.Logger;

/**
 * 日志服务启动类
 */
public class StartLog {
    private static Logger logger = DefaultLoggerFacotry.getLogger(StartLog.class);

    public static void main(String[] args) {
        logger.info(LogFormatUtil.getFormatMsg(new String[]{"module", "msg"},
                new Object[]{"UserLogTask", "prepare to start..."}));
        try{
            //加载spring配置文件
            SpringHelper.init(new String[] { "classpath:/spring/applicationContext.xml" });
            
			TaskScheduleManager taskManager = SpringHelper.getBean("taskScheduleManager");
			LogConfig config = SpringHelper.getBean("logConfig");
			taskManager.shedule("UserLogTask", UserLogTask.class, config.getSaveLogCron(), null);
			
            synchronized(StartLog.class){
                //等待
                StartLog.class.wait();
            }
        }catch(Exception e){
            logger.error(LogFormatUtil.getFormatMsg(new String[]{"module", "msg"},
                    new Object[]{"UserLogTask", "has some problem in the start..."}), e);
        }
        logger.info(LogFormatUtil.getFormatMsg(new String[]{"module", "msg"},
                new Object[]{"UserLogTask", "start successfully..."}));
    }
}
